import { useRoute } from "@/hooks/useRoute";
import { Button as AntButton, ButtonProps } from "antd";
import { FC, useMemo } from "react";

interface AuthButtonProps extends ButtonProps {
    permission?: string;
}

const Button: FC<AuthButtonProps> = ({ permission, ...props }) => {
    const { permissions } = useRoute();
    const inPermissions = useMemo(() => permissions.some(item => item.key === permission), [permissions, permission]);
    return inPermissions && <AntButton {...props} />;
};

export default Button;
